#include "listitem.h"
#include "listmodel.h"
#include <QDebug>

ListItem::ListItem(QObject *parent) :
    QObject(parent)
{
}

ListItem::ListItem(int id, Artikl item, float quantity, bool bought, QString unit, bool isAGroup, int groupNumber, int index){
    m_ListItemId=id;
    m_ItemId=item.dajId();
    m_ItemName=item.dajImeArtikla();

    Grupa grupa=item.dajGrupu();

    m_GroupId=grupa.dajId();
    m_GroupName=grupa.dajImeGrupe();

    m_Quantity=quantity;
    m_Unit=unit;

    m_Bought=bought;

    m_IsAGroup=isAGroup;

    m_GroupNumber=groupNumber;

    m_Index=index;
}

ListItem::~ListItem(){
}

int ListItem::listItemId(){
    return m_ListItemId;
}

int ListItem::itemId(){
    return m_ItemId;
}

QString ListItem::itemName(){
    return m_ItemName;
}

int ListItem::groupId(){
    return m_GroupId;
}

QString ListItem::groupName(){
    return m_GroupName;
}

float ListItem::quantity(){
    return m_Quantity;
}

QString ListItem::unit(){
    return m_Unit;
}

bool ListItem::isBought(){
    return m_Bought;
}

bool ListItem::isAGroup(){
    return m_IsAGroup;
}

int ListItem::groupNumber(){
    return m_GroupNumber;
}

int ListItem::index(){
    return m_Index;
}

void ListItem::setBought(bool newBought)
{
    if(newBought != m_Bought)
    {
        m_Bought=newBought;
        //emit boughtChanged(newBought);
        emit dataChanged();
    }
}

void ListItem::setQuantity(float newQuantity){
    if (newQuantity!=m_Quantity){
        m_Quantity=newQuantity;
        emit dataChanged();
    }
}

void ListItem::setUnit(QString newUnit){
    if (QString::compare(m_Unit, newUnit, Qt::CaseSensitive) != 0){
        m_Unit=newUnit;
        emit dataChanged();
    }
}
